package com.fc.test.service;

import java.util.List;
import java.util.Arrays;

import com.fc.test.mapper.auto.ForeClassMapper;
import com.fc.test.model.auto.ForeClass;
import com.fc.test.model.auto.ForeClassExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.ForeClassMessageMapper;
import com.fc.test.model.auto.ForeClassMessage;
import com.fc.test.model.auto.ForeClassMessageExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 *  ForeClassMessageService
 * @Title: ForeClassMessageService.java 
 * @Package com.fc.test.service 
 * @author fuce_自动生成
 * @email 115889198@qq.com
 * @date 2020-04-19 15:29:29  
 **/
@Service
public class ForeClassMessageService implements BaseService<ForeClassMessage, ForeClassMessageExample>{
	@Autowired
	private ForeClassMessageMapper foreClassMessageMapper;
	@Autowired
	ForeClassMapper foreClassMapper;


	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<ForeClassMessage> list(Tablepar tablepar,String name){
	        ForeClassMessageExample testExample=new ForeClassMessageExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
				ForeClassExample foreClassExample=new ForeClassExample();
				foreClassExample.or().andNameEqualTo(name);
				List<ForeClass> list1=foreClassMapper.selectByExample(foreClassExample);
				if(list1.size()!=0)name=list1.get(0).getId();
			}

	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andClassIdLike("%"+name+"%");
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<ForeClassMessage> list= foreClassMessageMapper.selectByExample(testExample);
	        PageInfo<ForeClassMessage> pageInfo = new PageInfo<ForeClassMessage>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {

			List<String> lista=Convert.toListStrArray(ids);
			ForeClassMessageExample example=new ForeClassMessageExample();
			example.createCriteria().andIdIn(lista);
			return foreClassMessageMapper.deleteByExample(example);


	}


	@Override
	public ForeClassMessage selectByPrimaryKey(String id) {

			return foreClassMessageMapper.selectByPrimaryKey(id);

	}


	@Override
	public int updateByPrimaryKeySelective(ForeClassMessage record) {
		return foreClassMessageMapper.updateByPrimaryKeySelective(record);
	}


	/**
	 * 添加
	 */
	@Override
	public int insertSelective(ForeClassMessage record) {

		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());


		return foreClassMessageMapper.insertSelective(record);
	}


	@Override
	public int updateByExampleSelective(ForeClassMessage record, ForeClassMessageExample example) {

		return foreClassMessageMapper.updateByExampleSelective(record, example);
	}


	@Override
	public int updateByExample(ForeClassMessage record, ForeClassMessageExample example) {

		return foreClassMessageMapper.updateByExample(record, example);
	}

	@Override
	public List<ForeClassMessage> selectByExample(ForeClassMessageExample example) {

		return foreClassMessageMapper.selectByExample(example);
	}


	@Override
	public long countByExample(ForeClassMessageExample example) {

		return foreClassMessageMapper.countByExample(example);
	}


	@Override
	public int deleteByExample(ForeClassMessageExample example) {

		return foreClassMessageMapper.deleteByExample(example);
	}

	/**
	 * 检查name
	 * @param foreClassMessage
	 * @return
	 */
	public int checkNameUnique(ForeClassMessage foreClassMessage){
		ForeClassMessageExample example=new ForeClassMessageExample();
		example.createCriteria().andClassIdEqualTo(foreClassMessage.getClassId());
		List<ForeClassMessage> list=foreClassMessageMapper.selectByExample(example);
		return list.size();
	}


}
